package com.example.www.Service;

import com.example.www.Entity.Photo;
import com.example.www.Mapper.PhotoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PhotoService {

    @Autowired
    private PhotoMapper photoMapper;

    @Value("${qiniu.url}")
    private String qiniuUrl;

    public List<Photo> getPhotoList() {
        return photoMapper.selectList(null);
    }

    public Photo getPhoto(int id){
        return photoMapper.selectById(id);
    }

    public void addPhoto(String key){
        Photo photo=new Photo();
        photo.setPhotolink(qiniuUrl+key);
        photoMapper.insert(photo);
    }

    public void deletePhoto(int id){
        photoMapper.deleteById(id);
    }
}
